require(['gaodeMap'], function () {
    var mapObj = new MapGaoDe(107.49023438, 36.24427318, 2);

    var bus;

    function clear() {
        if(bus){
            bus.clear();
        }
    }

    window.showMapLocation = function (data) {
        clear();
        var info = '';
        //item.direction方向
        if (data.licPltNo) {
            info += '车牌号 : {0}<br>'.format(data.licPltNo);
        }
        if (data.driverName) {
            info += '驾驶员 : {0}<br>'.format(data.driverName);
        }
        if (data.inoutTime) {
            info += '发生时间 : {0}<br>'.format(data.inoutTime);
        }
        if (data.speed) {
            info += '车速 : {0}Km/h<br>'.format(data.speed);
        }

        var bus = new Bus(mapObj, data.licPltNo, data.loLgt, data.loLtt, data.direction, info);
        mapObj.mapMoveTo(data.loLgt, data.loLtt);
        bus.show();
    }

    window.showMapLocationForArray = function (data) {
        clear();
        $.each(data,function(index,item){
            var info = '';
            //item.direction方向
            if (item.licPltNo) {
                info += '车牌号 : {0}<br>'.format(item.licPltNo);
            }
            if (item.driverName) {
                info += '驾驶员 : {0}<br>'.format(item.driverName);
            }
            if (item.inoutTime) {
                info += '发生时间 : {0}<br>'.format(item.inoutTime);
            }
            if (item.speed) {
                info += '车速 : {0}Km/h<br>'.format(item.speed);
            }
            var bus = new Bus(mapObj, item.licPltNo, item.loLgt, item.loLtt, item.direction, info);
            mapObj.mapMoveTo(item.loLgt, item.loLtt);
            bus.show();
        });
    }


    //画多边形（电子围栏）
    function createPolygon(electFencInfo) {
        var polygonArr = [];
        $.each(electFencInfo.list, function (i, item) {
            polygonArr.push([item.fencLgt, item.fencLtt]);
            if (i == 0) {
                mapObj.setMapCenterAndLevel(item.fencLgt, item.fencLtt, 13);
            }
        });

        var polygon = new AMap.Polygon({
            path: polygonArr,//设置多边形边界路径
            strokeColor: "#FF33FF", //线颜色
            strokeOpacity: 0.2, //线透明度
            strokeWeight: 3,    //线宽
            fillColor: "#1791fc", //填充色
            fillOpacity: 0.35//填充透明度
        });
        polygon.setMap(mapObj.map);
    }

    //画圈（电子围栏）
    function createCircle(electFencInfo) {
        var circle = new AMap.Circle({
            center: new AMap.LngLat(electFencInfo.coreLgt, electFencInfo.coreLtt),// 圆心位置
            radius: electFencInfo.coreRadius, //半径
            strokeColor: "#F33", //线颜色
            strokeOpacity: 1, //线透明度
            strokeWeight: 3, //线粗细度
            fillColor: "#ee2200", //填充颜色
            fillOpacity: 0.35//填充透明度
        });
        circle.setMap(mapObj.map);
        mapObj.setMapCenterAndLevel(electFencInfo.coreLgt, electFencInfo.coreLtt, 13);
    }

    //清除地图
    window.clear = function () {
        mapObj.map.clearMap();
    };

    /**
     * 显示单个电子围栏信息
     * @param electFencInfo {object} 电子围栏信息
     */
    window.showSingleElectFencMap = function (electFencInfo) {
        if (electFencInfo.fencType == 1) {
            createPolygon(electFencInfo);
        } else {
            createCircle(electFencInfo);
        }
    };
});